#include<bits/stdc++.h>
using namespace std;
#define inc(i,l,r) for(int i=l;i<=r;++i)
#define dec(i,r,l) for(int i=r;i>=l;--i) 
const int N = 505;
int n, m, T, k, x1[N][N], x2[N][N], x3[N * 4], x32[N * 4];
int co[N][N], ans, ans2;
int main(){
	freopen("traffic.in", "r", stdin);
	freopen("traffic.out", "w", stdout);
	cin >> n >> m >> T;
	inc(i, 1, n-1) inc(j, 1, m) cin >> x1[i][j];
	inc(i, 1, n) inc(j, 1, m-1) cin >> x2[i][j];
	while(T--) {
		cin >> k;  
		inc(i, 1, k) {
			int x, p, t;   cin >> x >> p >> t;
			x3[p] = x, x32[p] = t;
			if(t==0) ans += x;    else ans2 += x;
		}
		cout << min(ans, ans2) << endl;
	}
	return 0;
}
